home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / signal / fftconv.m < prev    next >
Text File  |  1997-03-07  |  2KB  |  62 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: fftconv (a, b [, N])
  21. ##
  22. ## c = fftconv (a, b) returns the convolution of the vectors a and b,
  23. ## a vector with length equal to length (a) + length (b) - 1.
  24. ## If a and b are the coefficient vectors of two polynomials, c is
  25. ## the coefficient vector of the product polynomial.
  26. ##
  27. ## The computation uses the FFT by calling fftfilt.  If the optional
  28. ## argument N is specified, an N-point FFT is used.
  29.  
  30. ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
  31. ## Created: 3 September 1994
  32. ## Adapted-By: jwe
  33.  
  34. function c = fftconv (a, b, N)
  35.  
  36.   if (nargin < 2 || nargin > 3)
  37.     usage ("fftconv (b, x [, N])");
  38.   endif
  39.  
  40.   if (! (is_vector (a) && is_vector (b)))
  41.     error ("fftconv:  both a and b should be vectors");
  42.   endif
  43.   la = length (a);
  44.   lb = length (b);
  45.   if ((la == 1) || (lb == 1))
  46.     c = a * b;
  47.   else
  48.     lc = la + lb - 1;
  49.     a(lc) = 0;
  50.     b(lc) = 0;
  51.     if (nargin == 2)
  52.       c = fftfilt (a, b);
  53.     else
  54.       if !(is_scalar (N))
  55.     error ("fftconv: N has to be a scalar");
  56.       endif
  57.       c = fftfilt (a, b, N);
  58.     endif
  59.   endif
  60.  
  61. endfunction
  62.